package com.zt.java.back;

public class Diagram {
    public static void main(String args[]){

        String points[] = {"A","B","C"};
        int weight[] = new int []{1,2,2};
        String path[][] = new String[][]{{"A","B"}, {"B", "C"}, {"A", "C"}};
        String headPoint = "A";
        int maxValue = PathPlan(points,weight,path,headPoint);
        System.out.println(maxValue);
    }
    public static int PathPlan(String points[],int[] weight,String path[][],String headPoint){
        int maxValue = 0;
        int pathNum = path.length;
        for(int i=0; i< pathNum;i++){
            int pathValue = 0;
            String startPoint = path[i][0];
            String endPoint = path[i][1];
            if(startPoint.equals(headPoint)){
                pathValue += getWeightByPoint(points,weight,startPoint);
                pathValue += getWeightByPoint(points,weight,endPoint);
                String findPath = findByStartPoint(path,endPoint);
                while(findPath!=null){
                    pathValue += getWeightByPoint(points,weight,findPath);
                    findPath = findByStartPoint(path,findPath);
                }
            }
            maxValue = maxValue > pathValue ? maxValue : pathValue;
        }
        return  maxValue;
    }
    public static int  getWeightByPoint(String points[],int[] weight,String point){
        int value = 0;
        for(int i=0; i< points.length;i++){
            if(point.equals(points[i])){
                value = weight[i];
            }
        }
        return value;
    }
    public static String findByStartPoint(String path[][],String startPoint){
        String endPoint = null;
        for(int i=0; i< path.length;i++){
            String point = path[i][0];
            if(point.equals(startPoint)){
                endPoint = path[i][1];
                break;
            }
        }
        return endPoint;
    }
}


